package GUI;

import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JList;

import java.awt.event.MouseAdapter;

public class Search extends JFrame {

	private JPanel contentPane;
	private Order o;
	private Rent r;
	private Product p;
	private Item i;
	private Member m;
	private Staff st;
	private Discount dis;
	private Delivery del;
	private JTextField txtSearch;

	/**
	 * Create the frame.
	 */
	public Search(String s) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 290, 270);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txtSearch = new JTextField();
		txtSearch.setText("search...");
		txtSearch.setBounds(10, 11, 150, 20);
		contentPane.add(txtSearch);
		txtSearch.setColumns(10);
		
		JButton btnSearch = new JButton("Search");
		btnSearch.setBounds(170, 10, 89, 23);
		contentPane.add(btnSearch);
		
		JList list = new JList();
		list.setBounds(10, 47, 249, 140);
		contentPane.add(list);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				MainMenu.getInstance().setVisible(true);
				dispose();
			}
		});
		btnCancel.setBounds(10, 198, 89, 23);
		contentPane.add(btnCancel);
		
		btnMng(s);
		
	}

	private void btnMng(String s) 
	{
		JButton btnMng = new JButton("Manage");
		switch(s){
		case "o":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					o= new Order(""); o.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(170, 198, 89, 23);
			contentPane.add(btnMng);
			
			break;
		case "r":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					r= new Rent(""); r.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(170, 198, 89, 23);
			contentPane.add(btnMng);;
			break;
		case "i":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					i= new Item(""); i.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(170, 198, 89, 23);
			contentPane.add(btnMng);
			break;
		case "p": 
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					p= new Product(""); p.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(170, 198, 89, 23);
			contentPane.add(btnMng);
			break;
		
		case "m":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					m= new Member("","p"); m.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(170, 198, 89, 23);
			contentPane.add(btnMng);
			break;
		case "s":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					st = new Staff(""); st.setVisible(true); dispose();
				}
			});
			btnMng.setBounds(170, 198, 89, 23);
			contentPane.add(btnMng);
			break;
		case "dis":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					dis= new Discount(""); dis.setVisible(true); dispose();
				}
			});
				btnMng.setBounds(170, 198, 89, 23);
				contentPane.add(btnMng);
			break;
		case "del":
			btnMng.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					del= new Delivery(""); del.setVisible(true); dispose();
				}
			});
				btnMng.setBounds(170, 198, 89, 23);
				contentPane.add(btnMng);
			break;
		}
		
	}

}
